import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '批次号',
    align:"center",
    dataIndex: 'batchDescription'
   },
   {
    title: '投入品名称',
    align:"center",
    dataIndex: 'input',
    customRender:(data) =>{
      return data.record.inputs.name
    },
   },
   {
    title: '规格',
    align:"center",
    dataIndex: 'specifications',
    customRender:(data) =>{
      return data.record.specifications
    },
   },
   {
    title: '采购数量(kg)',
    align:"center",
    dataIndex: 'number'
   },
   {
    title: '费用(元)',
    align:"center",
    dataIndex: 'cost'
   },
   {
    title: '经销商',
    align:"center",
    dataIndex: 'distributor'
   },
   {
    title: '采购时间',
    align:"center",
    dataIndex: 'buyTime',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '采购人',
    align:"center",
    dataIndex: 'purchaser'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "批次号",
    field: 'batchDescription',
    component: 'Input',
    colProps: {span: 6},
  }
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '投入品种类',
    field: 'input',
    component: 'JTreeSelect',
    componentProps: {
      dict: "t_classification,name,id",
      pidField: "pid",
      pidValue: "1690898175602962434",
      hasChildField: "has_child",
    },
    // dynamicRules: ({model,schema}) => {
    //   return [
    //     { required: true, message: '请选择投入品种类!'},
    //   ];
    //  },
  },
  {
    label: '投入品',
    field: 'inputsId',
    slot:'select',
    component: 'JSelectInput',
    componentProps: {
      // dictCode: 't_inputs,name,id',
      placeholder: '请选择投入品',
      options: []
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择投入品!'},
      ];
    },
  },
  {
    label: '批次号',
    field: 'batchDescription',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入批次号!'},
          ];
     },
  },
  {
    label: '规格',
    field: 'specifications',
    component: 'Input',
  },
  {
    label: '采购数量',
    field: 'number',
    component: 'InputNumber',
    componentProps: {
      addonAfter: 'KG'
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入采购数量!'},
          ];
     },
  },
  {
    label: '费用',
    field: 'cost',
    component: 'InputNumber',
    componentProps: {
      addonAfter: '元'
    },
  },
  {
    label: '经销商',
    field: 'distributor',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入经销商!'},
          ];
     },
  },
  {
    label: '采购时间',
    field: 'buyTime',
    component: 'DatePicker',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入采购时间!'},
          ];
     },
  },
  {
    label: '采购人',
    field: 'purchaser',
    component: 'Input',
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
